﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ParseControls
{

    public class FwCheckBox : CheckBox
    {
        public CheckBoxType CheckBoxVisualType
        {
            get { return (CheckBoxType)GetValue(CheckBoxVisualTypeProperty); }
            set { SetValue(CheckBoxVisualTypeProperty, value); }
        }
        public static readonly DependencyProperty CheckBoxVisualTypeProperty =
            DependencyProperty.Register("CheckBoxVisualType", typeof(CheckBoxType),
            typeof(FwCheckBox), new PropertyMetadata(CheckBoxType.CheckBox));

        public object TransportObject
        {
            get { return (object)GetValue(TransportObjectProperty); }
            set { SetValue(TransportObjectProperty, value); }
        }
        public static readonly DependencyProperty TransportObjectProperty =
            DependencyProperty.Register("TransportObject", typeof(object), typeof(FwCheckBox), new PropertyMetadata(null));

        public object TrueText
        {
            get { return (object)GetValue(TrueTextProperty); }
            set { SetValue(TrueTextProperty, value); }
        }
        public static readonly DependencyProperty TrueTextProperty =
            DependencyProperty.Register("TrueText", typeof(object), typeof(FwCheckBox), new PropertyMetadata("ON"));

        public object FalseText
        {
            get { return (object)GetValue(FalseTextProperty); }
            set { SetValue(FalseTextProperty, value); }
        }
        public static readonly DependencyProperty FalseTextProperty =
            DependencyProperty.Register("FalseText", typeof(object),
            typeof(FwCheckBox), new PropertyMetadata("OFF"));

        public Brush CheckBoxForeground
        {
            get { return (Brush)GetValue(CheckBoxForegroundProperty); }
            set { SetValue(CheckBoxForegroundProperty, value); }
        }
        public static readonly DependencyProperty CheckBoxForegroundProperty =
            DependencyProperty.Register("CheckBoxForeground", typeof(Brush),
            typeof(FwCheckBox), new PropertyMetadata(Brushes.DarkGray));

        public FwCheckBox()
            : base()
        { }
        static FwCheckBox()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(FwCheckBox),
                new FrameworkPropertyMetadata(typeof(FwCheckBox)));
        }

        // overrides 
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
        }
        protected override void OnChecked(RoutedEventArgs e)
        {
            base.OnChecked(e);

            if (TransportObject != null)
            {
                ParseCustomEventArgs args = new ParseCustomEventArgs("CheckBox:Checked");
                args.Object = TransportObject;
                ParseOne.InformationSending(args);
            }
        }
        protected override void OnUnchecked(RoutedEventArgs e)
        {
            base.OnUnchecked(e);

            if (TransportObject != null)
            {
                ParseCustomEventArgs args = new ParseCustomEventArgs("CheckBox:Unchecked");
                args.Object = TransportObject;
                ParseOne.InformationSending(args);
            }
        }
    }

    public enum CheckBoxType
    {
        Shuffle = 0,
        CheckBox = 1,
        Star = 2,
    }
}
